<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<title>振宇汽车美容商城-用户注册</title>
<link rel="stylesheet" href="login_up.css" />
    <link rel="shortcut icon" href="../images/favicon1.ico" />
</head>
<style type="text/css">
    body{
    	position:relative;
    	background:url('../images/bizhi.png') no-repeat;
    }
</style>
<body >
    <!-- 商城标题 -->
    <div class="car_name">
      <h2>振宇汽车美容商城-用户注册</h2>
    </div>
    <!-- 登录窗口 -->
    <div class="login_up">
      <ul>
        <h4>振宇汽车美容商城-<span style="font: skyblue;">用户注册</span></h4>
        <form action="login_up.php" method="post" >
          <li><input type="text" name="admin" placeholder="-请输入注册用户名-" /></li>
          <li><input type="password" name="password" placeholder="-请输入注册密码-" /></li>
          <li><input type="text" name="email" placeholder="-请输入注册邮箱-" /></li>
          <li><input type="text" name="phone" placeholder="-请输入手机号-" /></li>
          <li class="login">
            <input type="submit" name="login" value="注册" />
          </li>
          <li><a href="index.php">返回登录</a></li>
        </form>
      </ul>
    </div>
  </body>
</html>
<?php
	
	require 'db.php';
	//接收$_POST用户名、密码、邮箱、手机号
	$admin=$_POST['admin'];
	$password=$_POST['password'];
	$email=$_POST['email'];
	$phone=$_POST['phone'];
	if (isset($_POST['login'])){
	    //查看表user用户名是否存在或为空
	    $mysql = "SELECT * FROM tb_user WHERE us_name = '$admin'";
	    //result必需规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。
	    $select = mysqli_query($link,$mysql);
	    $num = mysqli_num_rows($select);//函数返回结果集中行的数量
	    if($admin == "" || $password == "" || $email == "" || $phone == "")
	    {
	        echo "<script>alert('请确认信息完整性，不要漏填信息哦！');</script>";
	        header('refresh:0;url=login_up.php');
	        exit;
	    }else if($num){
	        echo "<script>alert('用户名已存在!');</script>";
	        header('refresh:0;url=login_up.php');
	        exit;
	    }else{
	        $sql="insert into tb_user(us_name,us_pwd,us_email,us_phone) values('$admin','$password','$email','$phone')";
	        $result=mysqli_query($link,$sql);
	        //判断是否注册后显示内容
	        if(!$result)
	        {	            
	            echo "<script>alert('注册不成功！');</script>";
	            header('refresh:0;url=login_up.php');
	            exit;
	        }
	        else
	        {
	            echo "<script>alert('注册成功！');</script>";
	            header('refresh:0;url=index.php');
	            exit;
	            mysqli_free_result($result);
	            mysqli_close($link);
	        }
	    }
	}
	
	
?>
